home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4370 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  56 lines

  1. Path: jupiter.planet.net!usenet
  2. From: Chris Kemp <chrisk@paladn.com>
  3. Newsgroups: comp.lang.c
  4. Subject: kbhit and getche loop
  5. Date: 4 Feb 1996 01:14:23 GMT
  6. Organization: Paladin Consultants, Inc.
  7. Message-ID: <4f119f$7e7@jupiter.planet.net>
  8. NNTP-Posting-Host: denv11.planet.net
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.2N (Windows; I; 32bit)
  13.  
  14. I have the following code which I want to take characters from the stdin, and 
  15. append them onto a commandstring.  Inbetween processing the characters, the 
  16. computer has to ckeck some things, but if it gets a character, I want to append it 
  17. onto the commandstring.  When getche gets a {return}, I want the commandstring to 
  18. be processed.
  19.  
  20.  
  21. I think my problem is in processing the ch character, or perhaps comparing it to 
  22. '/n'.  Also, I couldn't concatenate ch directly onto commandstring, because ch is 
  23. an integer, and strcat wants a const char * in the second position.
  24.  
  25.  
  26. If anyone has some thoughts about hot to do this, I'd sure would like a good 
  27. suggestion.
  28.  
  29. TIA
  30.  
  31. do {                             // master command loop  
  32.         
  33.                while (!kbhit()){
  34.                 // get actual positions    
  35.                 
  36.                 gisilent=TRUE;
  37.                 for (i=0;i<=MAXAXIS;i++){ 
  38.                     *actualposition[i]=rcp(i);                 
  39.                 }  
  40.                 gisilent=FALSE;
  41.             }
  42.                         
  43.             int ch; 
  44.             char *charget;
  45.             ch=getche(); 
  46.             *charget=ch;
  47.             strcat(commandstring,charget);
  48.             
  49.             if (ch=='/n') {               
  50.                 parse(commandstring, delimiter);   //separate it into tokens 
  51. store in parsedarray[MAXWORDS][SIZE] 
  52.                 processcommandincommandstring();               
  53.                }
  54.  } while (0 EQ 0); //infinite loop
  55.  
  56.